package com.jilin.library.mapper;

import com.jilin.library.entity.Book;
import org.apache.ibatis.annotations.*;
import java.util.List;

@Mapper
public interface BookMapper {
    @Select("SELECT * FROM book")
    List<Book> findAll();
    
    @Select("SELECT * FROM book WHERE id = #{id}")
    Book findById(Integer id);
    
    @Insert("INSERT INTO book(isbn, title, author, publisher, price, stock) " +
            "VALUES(#{isbn}, #{title}, #{author}, #{publisher}, #{price}, #{stock})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insert(Book book);
    
    @Update("UPDATE book SET stock = stock + #{quantity} WHERE id = #{id}")
    int updateStock(@Param("id") Integer id, @Param("quantity") Integer quantity);
} 